<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Installs a proxy for mysqlnd connections</title>
 </head>
 <body class="docs"><div id="layout">
  <div id="layout-content"><div id="function.mysqlnd-uh-set-connection-proxy" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">mysqlnd_uh_set_connection_proxy</h1>
  <p class="verinfo">(PECL mysqlnd-uh &gt;= 1.0.0-alpha)</p><p class="refpurpose"><span class="refname">mysqlnd_uh_set_connection_proxy</span> &mdash; <span class="dc-title">Installs a proxy for mysqlnd connections</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.mysqlnd-uh-set-connection-proxy-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>mysqlnd_uh_set_connection_proxy</strong></span>
    ( <span class="methodparam"><span class="type"><a href="class.mysqlnduhconnection.html" class="type MysqlndUhConnection">MysqlndUhConnection</a></span> <code class="parameter reference">&$connection_proxy</code></span>
   [, <span class="methodparam"><span class="type"><a href="class.mysqli.html" class="type mysqli">mysqli</a></span> <code class="parameter reference">&$mysqli_connection</code></span>
  ] ) : <span class="type">bool</span></div>

  <p class="para rdfs-comment">
   Installs a proxy object to hook mysqlnd&#039;s connection objects methods.
   Once installed, the proxy will be used for all MySQL connections
   opened with <a href="ref.mysqli.html" class="link">mysqli</a>,
   <a href="ref.mysql.html" class="link">mysql</a> or
   <a href="ref.pdo_mysql.html" class="link">PDO_MYSQL</a>, assuming that the listed
   extensions are compiled to use the <a href="book.mysqlnd.html" class="link">mysqlnd</a>
   library.
  </p>
  <p class="para">
   The function can be disabled with
   <em><a href="mysqlnd-uh.configuration.html#ini.mysqlnd-uh.enable" class="link">mysqlnd_uh.enable</a></em>.
   If <em><a href="mysqlnd-uh.configuration.html#ini.mysqlnd-uh.enable" class="link">mysqlnd_uh.enable</a></em>
   is set to <strong><code>FALSE</code></strong> the function will not install the proxy and
   always return <strong><code>TRUE</code></strong>. Additionally, an error of the
   type <em>E_WARNING</em> may be emitted. The error message may
   read like <em>PHP Warning:  mysqlnd_uh_set_connection_proxy(): (Mysqlnd User Handler)
   The plugin has been disabled by setting the configuration parameter mysqlnd_uh.enable = false.
   The proxy has not been installed [...]</em>.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.mysqlnd-uh-set-connection-proxy-parameters">
  <h3 class="title">参数</h3>
  <dl>

   
    <dt>
<code class="parameter">connection_proxy</code></dt>

    <dd>

     <p class="para">
      A proxy object of type <a href="class.mysqlnduhconnection.html" class="classname">MysqlndUhConnection</a>.
     </p>
    </dd>

   
   
    <dt>
<code class="parameter">mysqli_connection</code></dt>

    <dd>

     <p class="para">
      Object of type <em>mysqli</em>.
      If given, the proxy will be set for this particular connection only.
     </p>
    </dd>

   
  </dl>

 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.mysqlnd-uh-set-connection-proxy-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   Returns <strong><code>TRUE</code></strong> on success.
   Otherwise, returns <strong><code>FALSE</code></strong>
  </p>
 </div>


<div class="refsect1 examples" id="refsect1-function.mysqlnd-uh-set-connection-proxy-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-2362">
    <p><strong>Example #1 <span class="function"><strong>mysqlnd_uh_set_connection_proxy()</strong></span> example</strong></p>
        <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$mysqli&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">mysqli</span><span style="color: #007700">(</span><span style="color: #DD0000">"localhost"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"root"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">""</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"test"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$mysqli</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">query</span><span style="color: #007700">(</span><span style="color: #DD0000">"SELECT&nbsp;'No&nbsp;proxy&nbsp;installed,&nbsp;yet'"</span><span style="color: #007700">);<br /><br />class&nbsp;</span><span style="color: #0000BB">proxy&nbsp;</span><span style="color: #007700">extends&nbsp;</span><span style="color: #0000BB">MysqlndUhConnection&nbsp;</span><span style="color: #007700">{<br />&nbsp;public&nbsp;function&nbsp;</span><span style="color: #0000BB">query</span><span style="color: #007700">(</span><span style="color: #0000BB">$res</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$query</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">printf</span><span style="color: #007700">(</span><span style="color: #DD0000">"%s(%s)\n"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">__METHOD__</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">var_export</span><span style="color: #007700">(</span><span style="color: #0000BB">func_get_args</span><span style="color: #007700">(),&nbsp;</span><span style="color: #0000BB">true</span><span style="color: #007700">));<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$ret&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">parent</span><span style="color: #007700">::</span><span style="color: #0000BB">query</span><span style="color: #007700">(</span><span style="color: #0000BB">$res</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$query</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">printf</span><span style="color: #007700">(</span><span style="color: #DD0000">"%s&nbsp;returns&nbsp;%s\n"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">__METHOD__</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">var_export</span><span style="color: #007700">(</span><span style="color: #0000BB">$ret</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">true</span><span style="color: #007700">));<br />&nbsp;&nbsp;&nbsp;return&nbsp;</span><span style="color: #0000BB">$ret</span><span style="color: #007700">;<br />&nbsp;}<br />}<br /></span><span style="color: #0000BB">mysqlnd_uh_set_connection_proxy</span><span style="color: #007700">(new&nbsp;</span><span style="color: #0000BB">proxy</span><span style="color: #007700">());<br /><br /></span><span style="color: #0000BB">$mysqli</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">query</span><span style="color: #007700">(</span><span style="color: #DD0000">"SELECT&nbsp;'mysqlnd&nbsp;rocks!'"</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$mysql&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">mysql_connect</span><span style="color: #007700">(</span><span style="color: #DD0000">"localhost"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"root"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">""</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"test"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">mysql_query</span><span style="color: #007700">(</span><span style="color: #DD0000">"SELECT&nbsp;'Ahoy&nbsp;Andrey!'"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$mysql</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$pdo&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">PDO</span><span style="color: #007700">(</span><span style="color: #DD0000">"mysql:host=localhost;dbname=test"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"root"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">""</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$pdo</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">query</span><span style="color: #007700">(</span><span style="color: #DD0000">"SELECT&nbsp;'Moin&nbsp;Johannes!'"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
    </div>

    <div class="example-contents"><p>以上例程会输出：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
proxy::query(array (
  0 =&gt; NULL,
  1 =&gt; &#039;SELECT \&#039;mysqlnd rocks!\&#039;&#039;,
))
proxy::query returns true
proxy::query(array (
  0 =&gt; NULL,
  1 =&gt; &#039;SELECT \&#039;Ahoy Andrey!\&#039;&#039;,
))
proxy::query returns true
proxy::query(array (
  0 =&gt; NULL,
  1 =&gt; &#039;SELECT \&#039;Moin Johannes!\&#039;&#039;,
))
proxy::query returns true
</pre></div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.mysqlnd-uh-set-connection-proxy-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member">
     <span class="function"><a href="mysqlnd_uh_set_statement_proxy.html" class="function" rel="rdfs-seeAlso">mysqlnd_uh_set_statement_proxy()</a> - Installs a proxy for mysqlnd statements</span>
    </li>
    <li class="member">
     <em><a href="mysqlnd-uh.configuration.html#ini.mysqlnd-uh.enable" class="link">mysqlnd_uh.enable</a></em>
    </li>
   </ul>
  </p>
 </div>


</div></div></div></body></html>